package com.dhx.dao;

import com.dhx.util.DbUtil;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

/**
 * @ClassName UserDao
 * @Author 邓皓轩
 * @Date 2024/11/2 下午3:12
 **/
public class UserDao {
    public boolean login(String username, String password) {
        //查询数据库，完成用户查询
        Connection conn = DbUtil.getConn();

        //查询用户表的sql
        String sql = "select * from userlist where name=? and pass=?";

        try {
            PreparedStatement preparedStatement = conn.prepareStatement(sql);
            preparedStatement.setString(1,username);
            preparedStatement.setString(2,password);
            ResultSet resultSet = preparedStatement.executeQuery();
            if (resultSet.next()){
                return true;
            }else {
                return false;
            }
        } catch (SQLException throwables) {
            throwables.printStackTrace();
        }

        return true;
    }
}
